// data/local/ChessDatabase.kt
package com.hwpt.chesedemo.data.local

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import android.content.Context
import com.hwpt.chesedemo.data.local.dao.SavedGameDao
import com.hwpt.chesedemo.data.local.entity.GameRecordEntity

@Database(
    entities = [GameRecordEntity::class],
    version = 1,
    exportSchema = false
)
abstract class ChessDatabase : RoomDatabase() {
    
    abstract fun savedGameDao(): SavedGameDao
    
    companion object {
        @Volatile
        private var INSTANCE: ChessDatabase? = null
        
        fun getInstance(context: Context): ChessDatabase {
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                    context.applicationContext,
                    ChessDatabase::class.java,
                    "chess_database"
                ).build()
                INSTANCE = instance
                instance
            }
        }
    }
}